
package xmldatabase;

import java.sql.*; //导包

public class DBConnection {

    private static Connection Conn; // 数据库连接对象

    // 数据库连接地址
    private static final String URL = "jdbc:mysql://10.100.169.200:3306/news_system?characterEncoding=utf8&useSSL=true";
    // 数据库的用户名
    private static final String UserName = "root";
    // 数据库的密码
    private static final String Password = "passqord";

    public static Connection getConnection() {

        try {
            Class.forName("com.mysql.jdbc.Driver"); // 加载驱动
            System.out.println("加载驱动成功!!!");
        } catch (ClassNotFoundException e) {
        }

        try {
            Conn = DriverManager.getConnection(URL, UserName, Password);
            System.out.println("连接数据库成功!!!");

            //返回连接对象
            return Conn;

        } catch (SQLException e) {
            return null;
        }
    }
}